package main.java.com.zyh.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

abstract class Animal {
    final static int NUM;
    static int count = 0;
    private String animalName;
    private int animalAge;
    static {
        NUM = 20;
        System.out.println("静态初始代码块执行完毕");
    }
    {
        System.out.println("创建了一个对象");
    }
    public Animal() {
        count++;
    }
    public Animal(String animalName, int animalAge) {
        this.animalName = animalName;
        this.animalAge = animalAge;
    }

    public int getAnimalAge() {
        return animalAge;
    }

    public String getAnimalName() {
        return animalName;
    }

    public void setAnimalAge(int animalAge) {
        this.animalAge = animalAge;
    }

    public void setAnimalName(String animalName) {
        this.animalName = animalName;
    }

    public void eat(){
        System.out.println("Animal is eating");
    }
    private void sleep(){
        System.out.println("Animal is sleeping");
    }

    @Override
    public String toString() {
        return "Animal{" +
                "animalName='" + animalName + '\'' +
                ", animalAge=" + animalAge +
                '}';
    }
}
class Dog extends Animal{
    private String dogName;

    public Dog() {
        this("",1);
    }
    public Dog(String animalName, int animalAge) {
        super(animalName, animalAge);
        this.dogName = "狗狗";
    }

    public String getDogName() {
        return dogName;
    }

    @Override
    public void eat() {
        System.out.println("Dog is eating");
    }
}
class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("Cat is eating");
    }
}
class Test{
    public static void main(String[] args) {
        Dog animal = new Dog("豆豆",10);
        System.out.println("姓名："+animal.getAnimalAge());
        System.out.println("年龄："+animal.getAnimalName());
        System.out.println("小名："+ animal.getDogName());
        animal.eat();
        Animal[] a = {new Dog(),new Cat()};
        for(Animal a1:a){
            a1.eat();
        }
        System.out.println(Animal.count);
        System.out.println(animal);
        List<Integer> lst = new ArrayList<>();
        lst.add(1);
        lst.add(2);
        lst.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });
        lst.forEach(temp-> System.out.println(temp));
    }
}